/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import machine.Bob;

/**
 *
 * @author Administrator
 */
public class Bob85 extends javax.swing.JFrame {

    private final byte segMap[] = {4,5,6,7,0,1,2,3};
    private final ExtendedFileFilter hex = new ExtendedFileFilter("Hex file", ".hex");
    
    private Bob m;
    
    /**
     * Creates new form Bob85
     */
    public Bob85() {
        initComponents();
        initEmulator();
    }

    private void initEmulator() {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screen.width-getSize().width)/2, (screen.height-getSize().height)/2); 
        
        Disp1.setSegmentMap(segMap);
        Disp2.setSegmentMap(segMap);
        Disp3.setSegmentMap(segMap);
        Disp4.setSegmentMap(segMap);
        Disp5.setSegmentMap(segMap);
        Disp6.setSegmentMap(segMap);
        
        m = new Bob();
        
        m.setDisp1(Disp1);
        m.setDisp2(Disp2);
        m.setDisp3(Disp3);
        m.setDisp4(Disp4);
        m.setDisp5(Disp5);
        m.setDisp6(Disp6);

        m.start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fc = new javax.swing.JFileChooser();
        dispPanel = new javax.swing.JPanel();
        Disp1 = new gui.SevenDisp();
        Disp2 = new gui.SevenDisp();
        Disp3 = new gui.SevenDisp();
        Disp4 = new gui.SevenDisp();
        Disp5 = new gui.SevenDisp();
        Disp6 = new gui.SevenDisp();
        keyPanel = new javax.swing.JPanel();
        Button0 = new javax.swing.JButton();
        Button1 = new javax.swing.JButton();
        Button2 = new javax.swing.JButton();
        Button3 = new javax.swing.JButton();
        Button4 = new javax.swing.JButton();
        Button5 = new javax.swing.JButton();
        Button6 = new javax.swing.JButton();
        Button7 = new javax.swing.JButton();
        Button8 = new javax.swing.JButton();
        Button9 = new javax.swing.JButton();
        ButtonA = new javax.swing.JButton();
        ButtonB = new javax.swing.JButton();
        ButtonC = new javax.swing.JButton();
        ButtonD = new javax.swing.JButton();
        ButtonE = new javax.swing.JButton();
        ButtonF = new javax.swing.JButton();
        ButtonRst = new javax.swing.JButton();
        ButtonGo = new javax.swing.JButton();
        ButtonVek1 = new javax.swing.JButton();
        ButtonVek2 = new javax.swing.JButton();
        ButtonSmem = new javax.swing.JButton();
        ButtonRec = new javax.swing.JButton();
        ButtonNext = new javax.swing.JButton();
        ButtonExec = new javax.swing.JButton();
        BoxDebug = new javax.swing.JCheckBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        mFile = new javax.swing.JMenu();
        mLoadRam = new javax.swing.JMenuItem();
        mSaveRam = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mExit = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("BOB-85");

        dispPanel.setBackground(new java.awt.Color(0, 0, 0));

        Disp1.setPointLeft(true);
        Disp1.setPointVisible(true);

        javax.swing.GroupLayout Disp1Layout = new javax.swing.GroupLayout(Disp1);
        Disp1.setLayout(Disp1Layout);
        Disp1Layout.setHorizontalGroup(
            Disp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp1Layout.setVerticalGroup(
            Disp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 104, Short.MAX_VALUE)
        );

        Disp2.setPointLeft(true);
        Disp2.setPointVisible(true);

        javax.swing.GroupLayout Disp2Layout = new javax.swing.GroupLayout(Disp2);
        Disp2.setLayout(Disp2Layout);
        Disp2Layout.setHorizontalGroup(
            Disp2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp2Layout.setVerticalGroup(
            Disp2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        Disp3.setPointLeft(true);
        Disp3.setPointVisible(true);

        javax.swing.GroupLayout Disp3Layout = new javax.swing.GroupLayout(Disp3);
        Disp3.setLayout(Disp3Layout);
        Disp3Layout.setHorizontalGroup(
            Disp3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp3Layout.setVerticalGroup(
            Disp3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        Disp4.setPointLeft(true);
        Disp4.setPointVisible(true);

        javax.swing.GroupLayout Disp4Layout = new javax.swing.GroupLayout(Disp4);
        Disp4.setLayout(Disp4Layout);
        Disp4Layout.setHorizontalGroup(
            Disp4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp4Layout.setVerticalGroup(
            Disp4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        Disp5.setPointLeft(true);
        Disp5.setPointVisible(true);

        javax.swing.GroupLayout Disp5Layout = new javax.swing.GroupLayout(Disp5);
        Disp5.setLayout(Disp5Layout);
        Disp5Layout.setHorizontalGroup(
            Disp5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp5Layout.setVerticalGroup(
            Disp5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        Disp6.setPointLeft(true);
        Disp6.setPointVisible(true);

        javax.swing.GroupLayout Disp6Layout = new javax.swing.GroupLayout(Disp6);
        Disp6.setLayout(Disp6Layout);
        Disp6Layout.setHorizontalGroup(
            Disp6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        Disp6Layout.setVerticalGroup(
            Disp6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 104, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout dispPanelLayout = new javax.swing.GroupLayout(dispPanel);
        dispPanel.setLayout(dispPanelLayout);
        dispPanelLayout.setHorizontalGroup(
            dispPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dispPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Disp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Disp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Disp3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Disp4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addComponent(Disp5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Disp6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9))
        );
        dispPanelLayout.setVerticalGroup(
            dispPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Disp1, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
            .addComponent(Disp2, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
            .addComponent(Disp3, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
            .addComponent(Disp4, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
            .addComponent(Disp5, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
            .addComponent(Disp6, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
        );

        getContentPane().add(dispPanel, java.awt.BorderLayout.PAGE_START);

        keyPanel.setBackground(new java.awt.Color(22, 22, 22));
        keyPanel.setAlignmentX(0.0F);

        Button0.setBackground(new java.awt.Color(33, 33, 33));
        Button0.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button0.setForeground(new java.awt.Color(240, 240, 240));
        Button0.setMnemonic(KeyEvent.VK_0);
        Button0.setText("0");
        Button0.setActionCommand("00");
        Button0.setFocusable(false);
        Button0.setPreferredSize(new java.awt.Dimension(38, 38));
        Button0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button1.setBackground(new java.awt.Color(33, 33, 33));
        Button1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button1.setForeground(new java.awt.Color(240, 240, 240));
        Button1.setMnemonic(KeyEvent.VK_1);
        Button1.setText("1");
        Button1.setActionCommand("01");
        Button1.setFocusable(false);
        Button1.setPreferredSize(new java.awt.Dimension(38, 38));
        Button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button2.setBackground(new java.awt.Color(33, 33, 33));
        Button2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button2.setForeground(new java.awt.Color(240, 240, 240));
        Button2.setMnemonic(KeyEvent.VK_2);
        Button2.setText("2");
        Button2.setActionCommand("02");
        Button2.setFocusable(false);
        Button2.setPreferredSize(new java.awt.Dimension(38, 38));
        Button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button3.setBackground(new java.awt.Color(33, 33, 33));
        Button3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button3.setForeground(new java.awt.Color(240, 240, 240));
        Button3.setMnemonic(KeyEvent.VK_3);
        Button3.setText("3");
        Button3.setActionCommand("03");
        Button3.setFocusable(false);
        Button3.setPreferredSize(new java.awt.Dimension(38, 38));
        Button3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button4.setBackground(new java.awt.Color(33, 33, 33));
        Button4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button4.setForeground(new java.awt.Color(240, 240, 240));
        Button4.setMnemonic(KeyEvent.VK_4);
        Button4.setText("4");
        Button4.setActionCommand("04");
        Button4.setFocusable(false);
        Button4.setPreferredSize(new java.awt.Dimension(38, 38));
        Button4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button5.setBackground(new java.awt.Color(33, 33, 33));
        Button5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button5.setForeground(new java.awt.Color(240, 240, 240));
        Button5.setMnemonic(KeyEvent.VK_5);
        Button5.setText("5");
        Button5.setActionCommand("05");
        Button5.setFocusable(false);
        Button5.setPreferredSize(new java.awt.Dimension(38, 38));
        Button5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button6.setBackground(new java.awt.Color(33, 33, 33));
        Button6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button6.setForeground(new java.awt.Color(240, 240, 240));
        Button6.setMnemonic(KeyEvent.VK_6);
        Button6.setText("6");
        Button6.setActionCommand("06");
        Button6.setFocusable(false);
        Button6.setPreferredSize(new java.awt.Dimension(38, 38));
        Button6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button7.setBackground(new java.awt.Color(33, 33, 33));
        Button7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button7.setForeground(new java.awt.Color(240, 240, 240));
        Button7.setMnemonic(KeyEvent.VK_7);
        Button7.setText("7");
        Button7.setActionCommand("07");
        Button7.setFocusable(false);
        Button7.setPreferredSize(new java.awt.Dimension(38, 38));
        Button7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button8.setBackground(new java.awt.Color(33, 33, 33));
        Button8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button8.setForeground(new java.awt.Color(240, 240, 240));
        Button8.setMnemonic(KeyEvent.VK_8);
        Button8.setText("8");
        Button8.setActionCommand("08");
        Button8.setFocusable(false);
        Button8.setPreferredSize(new java.awt.Dimension(38, 38));
        Button8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        Button9.setBackground(new java.awt.Color(33, 33, 33));
        Button9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Button9.setForeground(new java.awt.Color(240, 240, 240));
        Button9.setMnemonic(KeyEvent.VK_9);
        Button9.setText("9");
        Button9.setActionCommand("09");
        Button9.setFocusable(false);
        Button9.setPreferredSize(new java.awt.Dimension(38, 38));
        Button9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonA.setBackground(new java.awt.Color(33, 33, 33));
        ButtonA.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonA.setForeground(new java.awt.Color(240, 240, 240));
        ButtonA.setMnemonic(KeyEvent.VK_A);
        ButtonA.setText("A");
        ButtonA.setActionCommand("0A");
        ButtonA.setFocusable(false);
        ButtonA.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonB.setBackground(new java.awt.Color(33, 33, 33));
        ButtonB.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonB.setForeground(new java.awt.Color(240, 240, 240));
        ButtonB.setMnemonic(KeyEvent.VK_B);
        ButtonB.setText("B");
        ButtonB.setActionCommand("0B");
        ButtonB.setFocusable(false);
        ButtonB.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonC.setBackground(new java.awt.Color(33, 33, 33));
        ButtonC.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonC.setForeground(new java.awt.Color(240, 240, 240));
        ButtonC.setMnemonic(KeyEvent.VK_C);
        ButtonC.setText("C");
        ButtonC.setActionCommand("0C");
        ButtonC.setFocusable(false);
        ButtonC.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonD.setBackground(new java.awt.Color(33, 33, 33));
        ButtonD.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonD.setForeground(new java.awt.Color(240, 240, 240));
        ButtonD.setMnemonic(KeyEvent.VK_D);
        ButtonD.setText("D");
        ButtonD.setActionCommand("0D");
        ButtonD.setFocusable(false);
        ButtonD.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonE.setBackground(new java.awt.Color(33, 33, 33));
        ButtonE.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonE.setForeground(new java.awt.Color(240, 240, 240));
        ButtonE.setMnemonic(KeyEvent.VK_E);
        ButtonE.setText("E");
        ButtonE.setActionCommand("0E");
        ButtonE.setFocusable(false);
        ButtonE.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonF.setBackground(new java.awt.Color(33, 33, 33));
        ButtonF.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonF.setForeground(new java.awt.Color(240, 240, 240));
        ButtonF.setMnemonic(KeyEvent.VK_F);
        ButtonF.setText("F");
        ButtonF.setActionCommand("0F");
        ButtonF.setFocusable(false);
        ButtonF.setPreferredSize(new java.awt.Dimension(38, 38));
        ButtonF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonRst.setBackground(new java.awt.Color(33, 33, 33));
        ButtonRst.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonRst.setForeground(new java.awt.Color(240, 240, 240));
        ButtonRst.setText("Rst");
        ButtonRst.setFocusable(false);
        ButtonRst.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonRst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonResetAction(evt);
            }
        });

        ButtonGo.setBackground(new java.awt.Color(33, 33, 33));
        ButtonGo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonGo.setForeground(new java.awt.Color(240, 240, 240));
        ButtonGo.setText("Go");
        ButtonGo.setActionCommand("10");
        ButtonGo.setFocusable(false);
        ButtonGo.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonVek1.setBackground(new java.awt.Color(33, 33, 33));
        ButtonVek1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonVek1.setForeground(new java.awt.Color(240, 240, 240));
        ButtonVek1.setText("Vek1");
        ButtonVek1.setActionCommand("40");
        ButtonVek1.setFocusable(false);
        ButtonVek1.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonVek1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonVek2.setBackground(new java.awt.Color(33, 33, 33));
        ButtonVek2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonVek2.setForeground(new java.awt.Color(240, 240, 240));
        ButtonVek2.setText("Vek2");
        ButtonVek2.setActionCommand("50");
        ButtonVek2.setFocusable(false);
        ButtonVek2.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonVek2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonSmem.setBackground(new java.awt.Color(33, 33, 33));
        ButtonSmem.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonSmem.setForeground(new java.awt.Color(240, 240, 240));
        ButtonSmem.setText("Smem");
        ButtonSmem.setActionCommand("20");
        ButtonSmem.setFocusable(false);
        ButtonSmem.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonSmem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonRec.setBackground(new java.awt.Color(33, 33, 33));
        ButtonRec.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonRec.setForeground(new java.awt.Color(240, 240, 240));
        ButtonRec.setText("Rec");
        ButtonRec.setActionCommand("30");
        ButtonRec.setFocusable(false);
        ButtonRec.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonRec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonNext.setBackground(new java.awt.Color(33, 33, 33));
        ButtonNext.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonNext.setForeground(new java.awt.Color(240, 240, 240));
        ButtonNext.setText("Next");
        ButtonNext.setActionCommand("60");
        ButtonNext.setFocusable(false);
        ButtonNext.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAction(evt);
            }
        });

        ButtonExec.setBackground(new java.awt.Color(33, 33, 33));
        ButtonExec.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ButtonExec.setForeground(new java.awt.Color(240, 240, 240));
        ButtonExec.setText("Exec");
        ButtonExec.setFocusable(false);
        ButtonExec.setPreferredSize(new java.awt.Dimension(89, 40));
        ButtonExec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonExecAction(evt);
            }
        });

        BoxDebug.setBackground(new java.awt.Color(22, 22, 22));
        BoxDebug.setForeground(new java.awt.Color(240, 240, 240));
        BoxDebug.setText("Debug");
        BoxDebug.setFocusable(false);
        BoxDebug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BoxDebugActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout keyPanelLayout = new javax.swing.GroupLayout(keyPanel);
        keyPanel.setLayout(keyPanelLayout);
        keyPanelLayout.setHorizontalGroup(
            keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(keyPanelLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(keyPanelLayout.createSequentialGroup()
                        .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ButtonVek1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ButtonSmem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ButtonNext, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41)
                        .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ButtonVek2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ButtonRec, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ButtonExec, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(keyPanelLayout.createSequentialGroup()
                        .addComponent(ButtonRst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ButtonGo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, keyPanelLayout.createSequentialGroup()
                        .addComponent(Button0, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button3, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, keyPanelLayout.createSequentialGroup()
                        .addComponent(Button4, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button5, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button6, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button7, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, keyPanelLayout.createSequentialGroup()
                        .addComponent(Button8, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Button9, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButtonA, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButtonB, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, keyPanelLayout.createSequentialGroup()
                        .addComponent(ButtonC, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButtonD, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButtonE, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButtonF, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(36, 36, 36))
            .addGroup(keyPanelLayout.createSequentialGroup()
                .addGap(252, 252, 252)
                .addComponent(BoxDebug)
                .addContainerGap())
        );
        keyPanelLayout.setVerticalGroup(
            keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(keyPanelLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButtonC, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ButtonD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButtonRst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonGo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(35, 35, 35)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Button8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(Button9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButtonVek1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonVek2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(34, 34, 34)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(Button4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(Button5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(Button6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(Button7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButtonRec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButtonSmem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(32, 32, 32)
                .addGroup(keyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButtonExec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ButtonNext, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38))
            .addGroup(keyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BoxDebug)
                .addContainerGap())
        );

        Button0.getAccessibleContext().setAccessibleName("");

        getContentPane().add(keyPanel, java.awt.BorderLayout.CENTER);

        mFile.setText("File");

        mLoadRam.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        mLoadRam.setText("Load RAM");
        mLoadRam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mLoadRamActionPerformed(evt);
            }
        });
        mFile.add(mLoadRam);

        mSaveRam.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        mSaveRam.setText("Save RAM");
        mSaveRam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mSaveRamActionPerformed(evt);
            }
        });
        mFile.add(mSaveRam);
        mFile.add(jSeparator1);

        mExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        mExit.setText("Exit");
        mExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mExitActionPerformed(evt);
            }
        });
        mFile.add(mExit);

        jMenuBar1.add(mFile);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonAction
        int keycode = Integer.parseInt(evt.getActionCommand(), 16);
        m.ButtonPressed(keycode);
    }//GEN-LAST:event_ButtonAction

    private void ButtonResetAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonResetAction
        m.ResetPressed();
    }//GEN-LAST:event_ButtonResetAction

    private void ButtonExecAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonExecAction
        m.ExecPressed();
    }//GEN-LAST:event_ButtonExecAction

    private void BoxDebugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BoxDebugActionPerformed
        boolean state = BoxDebug.isSelected();
        m.setDebug(state);
    }//GEN-LAST:event_BoxDebugActionPerformed

    private void mSaveRamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSaveRamActionPerformed
        m.stopEmulation();
        
        fc.setFileFilter(hex);
        fc.setDialogTitle("Save RAM to Hex file");
        int val = fc.showSaveDialog(this);
        
        if (val==JFileChooser.APPROVE_OPTION) {
            try {
                String s = fc.getSelectedFile().getCanonicalPath();
                if (!s.endsWith(hex.extension)) { s = s + hex.extension; }
                m.saveRam(s);
            } catch (IOException ex) {
                Logger.getLogger(Bob85.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        m.startEmulation();
    }//GEN-LAST:event_mSaveRamActionPerformed

    private void mLoadRamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mLoadRamActionPerformed
        m.stopEmulation();
        
        fc.setFileFilter(hex);        
        fc.setDialogTitle("Load RAM from Hex file");
        int val = fc.showOpenDialog(this);
        
        if (val==JFileChooser.APPROVE_OPTION) {
            try {
                m.loadRam(fc.getSelectedFile().getCanonicalPath());
            } catch (IOException ex) {
                Logger.getLogger(Bob85.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        m.startEmulation();        
    }//GEN-LAST:event_mLoadRamActionPerformed

    private void mExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mExitActionPerformed


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Bob85.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Bob85.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Bob85.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Bob85.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Bob85().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox BoxDebug;
    private javax.swing.JButton Button0;
    private javax.swing.JButton Button1;
    private javax.swing.JButton Button2;
    private javax.swing.JButton Button3;
    private javax.swing.JButton Button4;
    private javax.swing.JButton Button5;
    private javax.swing.JButton Button6;
    private javax.swing.JButton Button7;
    private javax.swing.JButton Button8;
    private javax.swing.JButton Button9;
    private javax.swing.JButton ButtonA;
    private javax.swing.JButton ButtonB;
    private javax.swing.JButton ButtonC;
    private javax.swing.JButton ButtonD;
    private javax.swing.JButton ButtonE;
    private javax.swing.JButton ButtonExec;
    private javax.swing.JButton ButtonF;
    private javax.swing.JButton ButtonGo;
    private javax.swing.JButton ButtonNext;
    private javax.swing.JButton ButtonRec;
    private javax.swing.JButton ButtonRst;
    private javax.swing.JButton ButtonSmem;
    private javax.swing.JButton ButtonVek1;
    private javax.swing.JButton ButtonVek2;
    private gui.SevenDisp Disp1;
    private gui.SevenDisp Disp2;
    private gui.SevenDisp Disp3;
    private gui.SevenDisp Disp4;
    private gui.SevenDisp Disp5;
    private gui.SevenDisp Disp6;
    private javax.swing.JPanel dispPanel;
    private javax.swing.JFileChooser fc;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel keyPanel;
    private javax.swing.JMenuItem mExit;
    private javax.swing.JMenu mFile;
    private javax.swing.JMenuItem mLoadRam;
    private javax.swing.JMenuItem mSaveRam;
    // End of variables declaration//GEN-END:variables
}
